package com.ciwong.epaper.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.util.DeviceUtil;
import com.ciwong.epaper.util.DisplayUtils;

/**
 * Created by yyf on 2017/10/10.
 */

public class HomeWorkHintDialog extends Dialog {
    private View workHintDialogView;
    private String workName;
    private String endTime;
    private String startTime;
    private String workOption;
    private String workMessage;
    private int offsetX;
    private int offsetY;
    private boolean isundowork = false;

    public HomeWorkHintDialog(@NonNull Context context, View workHintDialogView, String workName,
                              String startTime, String endTime, String workOption, String workMessage,
                              int offsetX, int offsetY, boolean isundowork) {
        super(context, R.style.round_corner_dialog);
        this.workHintDialogView = workHintDialogView;
        this.workName = workName;
        this.startTime = startTime;
        this.endTime = endTime;
        this.workOption = workOption;
        this.workMessage = workMessage;
        this.offsetX = offsetX;
        this.offsetY = offsetY;
        this.isundowork = isundowork;
        init();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    private void init() {
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = Gravity.CENTER;
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DeviceUtil.getDeviceWidth(getContext())
                - DisplayUtils.dip2px(getContext(), 16)
                , LinearLayout.LayoutParams.WRAP_CONTENT);


        addContentView(workHintDialogView, params);

        TextView tv_homework_name = findViewById(R.id.tv_homework_name);
        TextView tv_homework_start_time = findViewById(R.id.tv_homework_start_time);
        TextView tv_homework_end_time = findViewById(R.id.tv_homework_end_time);
        TextView tv_homework_tips = findViewById(R.id.tv_homework_tips);
        TextView tv_homework_option = findViewById(R.id.tv_homework_option);
        tv_homework_name.setText(workName);
        tv_homework_start_time.setText(startTime);
        tv_homework_end_time.setText(endTime);
        tv_homework_option.setText(workOption);
        tv_homework_name.setVisibility(View.VISIBLE);
        tv_homework_end_time.setVisibility(View.VISIBLE);
        tv_homework_start_time.setVisibility(View.VISIBLE);
        tv_homework_option.setVisibility(View.VISIBLE);
        if (null == workMessage || "".equals(workMessage)) {
            tv_homework_tips.setVisibility(View.GONE);
        } else {
            tv_homework_tips.setText(workMessage);
            tv_homework_tips.setVisibility(View.VISIBLE);
        }
        attributes.y = offsetY;
        window.setAttributes(attributes);

    }
}
